import 'package:flutter/material.dart';
import './res/listData.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
          appBar: AppBar(
            title: const Text('动态列表'),
          ),
          body: const MyHomePage()),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  // List<Widget> _initListData() {
  //   List<Widget> tempList = [];
  //   for (var i = 0; i < listData.length; i++) {
  //     tempList.add(ListTile(
  //       leading: Image.network("${listData[i]['imageUrl']}"),
  //       title: Text("${listData[i]['title']}"),
  //       subtitle: Text("${listData[i]["author"]}"),
  //     ));
  //   }
  //   return tempList;
  // }

  List<Widget> _initListData() {
    var tempList = listData.map((item) {
      return ListTile(
        leading: Image.network("${item['imageUrl']}"),
        title: Text("${item['title']}"),
        subtitle: Text("${item["author"]}"),
      );
    });
    return tempList.toList();
  }

  @override
  Widget build(BuildContext context) {
    print(listData.toList());
    return ListView(
      children: _initListData(),
    );
  }
}
